﻿using System;
using System.Collections.Generic;
using GameFramework.Battle.Core;
using Gameplay.PVE.Utils;
using RootMotion.FinalIK;
using UnityEngine;

namespace Gameplay.PVE.Survivor
{
    public class StickMovement : BulletMovement
    {
        protected bool isFinish = false;
        protected float lastHitTime;
        public override void Start()
        {
            bullet.Position = bullet.targetPosition;
            isFinish = false;
            lastHitTime = -1;
        }
        
        public override void Update()
        {
            if (isFinish)
            {
                return;
            }
            if (bullet.config.destroy_type == (int)EBulletDestroyType.OnReachTarget)
            {
                bullet.HitByCollision();
                isFinish = true;
            }
            else
            {
                if (lastHitTime < 0 || TimeManager.time - lastHitTime > bullet.config.element_interval)
                {
                    bullet.HitByCollision();
                    lastHitTime = TimeManager.time;
                }
            }
        }

        public override bool IsEnd()
        {
            return isFinish;
        }
    }
}
